package sdfi.lee.CE;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.HashMap;

import org.hibernate.Session;

import sdfi.lee.DAO.DAO;

public class CEMap {
	public static HashMap<String,Object> map=new HashMap<String,Object>();
	
	public static boolean isContainkey(String key) 
	{
		if(map.keySet().size()<=0)
		{
			try
			{
			Session session =DAO.openSession();
			Connection con=session.connection();
			Statement st=con.createStatement();
			ResultSet rs=st.executeQuery("select *FROM RELATION");
			while(rs.next())
			{
				map.put(rs.getString("name").toLowerCase(),rs.getString("cnname"));
			}
			}
			catch(Exception ee)
			{
				ee.printStackTrace();
			}
		}
			
		return map.containsKey(key.toLowerCase());
	}

	public static String getValueByKey(String key)
	{
		
		try
		{
		if(map.size()<=0) {
			Session session =DAO.openSession();
			Connection con=session.connection();
			Statement st=con.createStatement();
			ResultSet rs=st.executeQuery("select *FROM RELATION");
			while(rs.next())
			{
				map.put(rs.getString("name"),rs.getString("cnname"));
			}
			}
		if(map.size()<=0) return "未知";
		
		 return (String) map.get(key);
		}
		catch(Exception ee){
			ee.printStackTrace();
			return "未知";
		}
	}
}
